<template>
  <view class="normal-login-container">
    <!--左侧输入框搜索-->
    <search placeholder="请输入车牌号" @input="inputChange">

      <view class="flex right20 align-center" slot="right">
        <!--右侧缩略搜索-->
        <uni-icons type="tune" :color="isAllEmpty(queryParams)?'#333':'#1890FF'" @click="handleOpen" size="25"/>
      </view>
    </search>

    <mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback">
      <view class="item-wrap" v-for="(item,index) in list" :key="index" @click="goDetail(item)">

        <view class="title-wrap lineBottom10">
          <text>{{ item.vinNo || '' }} {{ item.carNo || '' }}</text>
          <text style="color: red" v-if="item.outStorageStatus=='1'">待出库</text>
		  <text style="color: #333333" v-if="item.outStorageStatus=='2'">已出库</text>
        </view>

        <view class="flex-row align-stretch">
          <view class="flex-col flex1">
            <view class="text-line">
              <text class="text-name">业务编号:</text>
              <text>{{ item.businessNo || '' }}</text>
            </view>
			<view class="text-line">
			  <text class="text-name">采购编号:</text>
			  <text class="text-value">{{ item.purchaseNo|filterNull }}</text>
			</view>
            <view class="text-line">
              <text class="text-name">品牌/车系/车型:</text>
              <text class="text-value">
                {{ item.brandName|filterNull }}{{ item.seriesName|filterNull }}{{ item.modelName|filterNull }}
              </text>
            </view>
            <view class="text-line">
              <text class="text-name">来源:</text>
              <text class="text-value">{{  handleLabel(dict.type.in_storage_source, item.purchaseSource) }}</text>
            </view>
          </view>
        </view>

        <view class="btn-wrap lineTop20">
			<button size="mini" v-if="item.saveFlag !==	2"
			        @click.stop="handleOperate(item)"
			        type="primary">下载交车单
			</button>
          <button size="mini" v-if="item.saveFlag !==	2"
                  @click.stop="handleEdit(item)"
                  type="primary">出库
          </button>
        </view>

      </view>
    </mescroll-body>

    <in-search ref="refInSearch" type='out' v-model="queryParams" @reset="reset" @confirm="confirm"/>
  </view>
</template>

<script>
import {queryList,downFile} from "@/api/storage/out.js";
import InSearch from "@/pages/StoragePage/compoents/inSearch.vue";

export default {
  components: {InSearch},
  dicts: ['in_storage_source'],
  data() {
    return {
      list: [],
      carNoVinNo: null,
      queryParams: {
        vinNo: "",
        carNo: "",
        ascription: "",
        purchaseSource: "",
        businessScopeCode: "",
        storageStatus: "",
        customerName: "",
      }
    }
  },
  onLoad() {
    uni.$on('refreshClue', call=>{
      this.mescroll.triggerDownScroll();
    })
  },
  methods: {
    //车架 车牌
    inputChange(val) {
	  this.queryParams.carNo = val
	  this.mescroll.resetUpScroll()
    },

    //搜索
    isAllEmpty() {

    },

    //打开搜索弹框
    handleOpen() {
      this.$refs.refInSearch.open()
    },


    //获取列表
    async upCallback(page) {
		let param = JSON.parse(JSON.stringify(this.queryParams))
		  if (param.storageStatus == 0) {
			param.storageStatus = ''
		  }
		  if (param.businessScopeCode == 0) {
			param.businessScopeCode = ''
		  }
      var params = {
        pageNum: page.num,
        pageSize: page.size,
        carNo: this.carNo,
		isShow:2,
        ...param,
      }
      try {
        const res = await queryList(params)
        //设置列表数据
        if (page.num === 1) this.list = []; //如果是第一页需手动制空列表
        res.rows.forEach(item => {
          item.check = false
        })
        this.list = this.list.concat(res.rows); //追加新数据
        this.mescroll.endBySize(res.rows.length, res.total);
      } catch (e) {
        //联网失败, 结束加载
        this.mescroll.endErr();
      }
    },

    goDetail(val) {
		let purchaseSource = val?.purchaseSource=='4'?1:2
		let url = `/pages/StoragePage/outStorage/info?inboundId=${val.inboundId}&id=${val.outboundId}&flowId=${val?.flowId || null}&viewType=0`
		this.$tab.navigateTo(url)
    },

    reset() {
      this.queryParams = {
        vinNo: "",
        carNo: "",
        ascription: "",
        purchaseSource: "",
        businessScopeCode: "",
        storageStatus: "",
        customerName: "",
      }
      this.mescroll.resetUpScroll()
    },

    confirm(val) {
      this.queryParams = val
      this.mescroll.resetUpScroll()
    },

    handleEdit(val) {
      let purchaseSource = val?.purchaseSource=='4'?1:2
      let url = `/pages/StoragePage/outStorage/info?inboundId=${val.inboundId}&id=${val.outboundId}&flowId=${val?.flowId || null}&viewType=1`
      this.$tab.navigateTo(url)
    },
	handleLabel(arr, type) {
		let name = ''
		arr.map((v) => {
		  if (type == v.value) {
			name = v.label;
		  }
		});
		return name
	},
	// 下载交车单
	handleOperate(info){
		this._download('/outStorage/download',info.outboundId,`交车单${info.outboundId}`)
	}
  }
}
</script>

<style lang="scss" scoped>

.radio {
  display: flex;
  align-items: center;
  font-size: 26rpx;
  margin-left: 10rpx;
}

.sel-wrap {
  padding: 0 0 0 10rpx;
}

</style>
